package flc.ast.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.PathUtils;
import com.stark.more.MorePrefUtil;
import com.stark.more.about.DefAboutActivity;

import java.io.File;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.DrawRecordActivity;
import flc.ast.activity.SettingActivity;
import flc.ast.databinding.FragmentMyBinding;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.base.BaseWebviewActivity;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link MyFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MyFragment extends BaseNoModelFragment<FragmentMyBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_my;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.rlDrawRecord.setOnClickListener(this);
        mDataBinding.ivSetting.setOnClickListener(this);
        mDataBinding.ivFeedback.setOnClickListener(this);
        mDataBinding.ivAgreement.setOnClickListener(this);
        mDataBinding.ivPrivacy.setOnClickListener(this);
        mDataBinding.ivAbout.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.rlDrawRecord://画板记录
                startActivity(DrawRecordActivity.class);
                break;
            case R.id.ivSetting://设置
                startActivity(SettingActivity.class);
                break;
            case R.id.ivFeedback://意见反馈
                BaseWebviewActivity.openFeedback(getActivity());
                break;
            case R.id.ivAgreement://用户协议
                BaseWebviewActivity.openAssetTerms(mContext);
                break;
            case R.id.ivPrivacy://隐私政策
                BaseWebviewActivity.openAssetPrivacy(getActivity());
                break;
            case R.id.ivAbout://关于我们
                startActivity(new Intent(getActivity(), DefAboutActivity.class));
                break;
        }
    }

    @Override
    protected void initData() {
        boolean showPersonalRecommend = MorePrefUtil.showPersonalRecommend();
        if (showPersonalRecommend) {
            //显示个性化开关控件
            mDataBinding.ivSetting.setVisibility(View.VISIBLE);
        } else {
            //隐藏个性化开关控件
            mDataBinding.ivSetting.setVisibility(View.GONE);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        getData();
    }

    private void getData() {
        List<File> files = FileUtils.listFilesInDir(PathUtils.getFilesPathExternalFirst() + Content.myDrawRecord);
        mDataBinding.tvDrawRecordNum.setText(getString(R.string.draw_num, files.size()));
    }

}